#!/bin/bash

TOMCAT_BASE_DIR=$1

stop_tomcat()
{
    TOMCAT_PID=`get_tomcat_pid`
    
    if [ ! -z "$TOMCAT_PID" ] ; then
    
        echo "stopping tomcat ..."
        
        sh $TOMCAT_BASE_DIR/bin/shutdown.sh
                                
        TOMCAT_PID=`get_tomcat_pid`
        if [ ! -z "$TOMCAT_PID" ] ; then
            kill -9 $TOMCAT_PID > /dev/null 2>&1
        fi
        echo "stopping tomcat ok"
    else
        echo "tomcat not running"
    fi
}

get_tomcat_pid(){    
    STR=`ps -C java -f --width 1000 | grep "$TOMCAT_BASE_DIR"|awk '{print $2}'`           
    echo $STR
}

stop_tomcat
